// components/FormId/formId.js
const app = getApp(),
  $extConfig = xhs.getExtConfigSync(),
  $config = require("../../config.js"),
  _ = require('../../pages/Common/underscore.js'),
  $appId = $extConfig.appId || $config.appId;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    className: {
      type: String,
      value: ''
    }
  },
  data: {
    showBackHome: false,
    showPrivacy: true
  },
  attached() {
    var pages = getCurrentPages(); //获取加载的页面
    var currentPage = pages[pages.length - 1]; //获取当前页面的对象
    var url = currentPage.route;
    // debugger
    xhs.setStorageSync('storagePath', url);
    // app.$getData('/user/employee/employee-info').then((data) => {
    //   if (currentPage.data.isRecharge && typeof currentPage.setRate === "function"){
    //     currentPage.setRate(data.data.wechatRate)
    //   }
    //   let userData = wx.getStorageSync('user'),
    //     config = wx.getStorageSync('config'),
    //     versionStorage = wx.getStorageSync('versionStorage');
    //   if (data.errCode == 0) {
    //     let versions = data.data.version
    //     if (!versionStorage || versionStorage == ''){

    //       wx.setStorageSync('versionStorage', data.data.version)
    //     } else if (versionStorage != data.data.version){

    //       app.$getData('/api/miniapp/login').then((data) => {
    //         if (data.errCode == 0) {
    //           wx.setStorageSync('user', data.data.userInfo);
    //           wx.setStorageSync('employeeInfo', data.data.employeeInfo);
    //           wx.setStorageSync('authoriz', data.data.userInfo.authoriz);
    //           wx.setStorageSync('versionStorage', versions)
    //         }
    //       })
    //     }
    //     if (!_.isEmpty(data.data)) {
    //       let userData = wx.getStorageSync('user'),
    //         config = wx.getStorageSync('config');
    //       let urlPath = wx.getStorageSync('storagePath')
    //       // [-1=未激活],[0=入职待审],[1=试用中],[2=已转正],[3=审核不通过],[4=转岗],[5=已离职],[6=退休]
    //       if (data.data.status == '-1') {
    //         app.$getData('/user/employee/activate-employee')
    //       } else if (data.data.status == '0' || data.data.status == '3' || data.data.status == '5' || data.data.status == '6') {
    //         this.fn(userData, config)
    //       }
    //     } else {
    //       let userData = wx.getStorageSync('user'),
    //           config = wx.getStorageSync('config');
    //       this.fn(userData, config)
    //     }
    //   } else {
    //     this.fn(userData, config)
    //   }
    // })
    this.setData({
      isMandatoryPhone: xhs.getStorageSync('isMandatoryPhone'),
      isQrcode: xhs.getStorageSync('isQrcode'),
      hasValidate: !!xhs.getStorageSync('user').mobile,
      authoriz: xhs.getStorageSync('authoriz')
    });
    app.login().then(() => {
      // app._getData('/user/user/extend-data').then((data) => {
      //   if (data.errCode == 0) {
      //     if(data.data.focusAuth && data.data.needAuth == '1'){//需要强制授权登录
      //       this.setData({
      //         isFocusAuth: true
      //       })                         
      //     }
      //     this.setData({
      //       showPrivacy:!((!this.data.authoriz && this.data.isQrcode) || this.data.isFocusAuth || (this.data.isMandatoryPhone == '1' && !this.data.hasValidate))
      //     })      
      //   }
      // })
    });
  },
  /**
   * 组件的方法列表
   */
  methods: {
    fn(userData, config) {
      return;
    },
    submitFormId(e) {
      app.$dealFormIds(e.detail.formId);
      this.triggerEvent('submit', e);
    },
    formagreeP() {
      this.triggerEvent('formagreeP');
    }
  }
});